<template>
  <view class="feedback-container">
    <!-- 状态栏 -->
    <view class="status-bar">

    </view>

    <!-- 标题栏 -->
    <view class="header">
      <view class="back-button" @click="goBack">
        <image src="/static/arrow-left.png" mode="aspectFit" class="back-icon"></image>
      </view>
      <text class="title">意见反馈</text>
      <view class="placeholder"></view>
    </view>

    <!-- 表单区域 -->
    <view class="form-container" v-if="!submitted">
      <text class="form-label">请写下您的反馈：</text>
      <view class="textarea-container">
        <textarea class="feedback-input" v-model="feedbackContent" placeholder="请输入反馈的具体内容"
          placeholder-style="color: #999999; font-size: 28rpx;" maxlength="500" />
      </view>

      <!-- 提交按钮 -->
      <button class="submit-button" @click="submitFeedback">提交</button>
    </view>

    <!-- 提交成功页面 -->
    <view class="success-container" v-if="submitted">
      <view class="success-icon">
        <view class="check-circle">
          <text class="check-mark">✓</text>
        </view>
      </view>
      <text class="success-text">反馈成功，感谢您的支持</text>
      <button class="return-button" @click="goBack">返回</button>
    </view>

    <!-- 底部导航条 -->
    <view class="bottom-bar"></view>
  </view>
</template>

<script>
import { submitFeedback } from '@/api/feedback';
export default {
  data() {
    return {
      feedbackContent: '',
      submitted: false
    }
  },
  methods: {
    goBack() {
      if (this.submitted) {
        uni.switchTab({
          url: '/pages/my/my'
        });
      } else {
        uni.navigateBack();
      }
    },
    submitFeedback() {
      if (!this.feedbackContent.trim()) {
        uni.showToast({
          title: '请输入反馈内容',
          icon: 'none'
        });
        return;
      }

      uni.showLoading({
        title: '提交中...'
      });
      
      submitFeedback({
        content: this.feedbackContent
      }).then(res => {
        uni.hideLoading();
        if (res.code === '00000') {
          this.submitted = true;
        } else {
          uni.showToast({
            title: res.msg || '提交失败，请重试',
            icon: 'none'
          });
        }
      }).catch(err => {
        uni.hideLoading();
        uni.showToast({
          title: '提交失败，请重试',
          icon: 'none'
        });
      });
    }
  }
}
</script>

<style lang="scss">
.feedback-container {
  min-height: 100vh;
  background-color: #f8f8f8;
  display: flex;
  flex-direction: column;
}

.status-bar {
  height: 88rpx;
  padding: 0 32rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #f8f8f8;

  .time {
    font-size: 32rpx;
    font-weight: bold;
    color: #000000;
  }

  .right-icons {
    display: flex;
    align-items: center;

    .signal,
    .wifi,
    .battery {
      background-color: #000000;
      margin-left: 12rpx;
    }

    .signal {
      width: 36rpx;
      height: 24rpx;
    }

    .wifi {
      width: 32rpx;
      height: 24rpx;
    }

    .battery {
      width: 48rpx;
      height: 24rpx;
      border-radius: 6rpx;
    }
  }
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20rpx 32rpx;
  background-color: #f8f8f8;

  .back-button {
    width: 60rpx;
    height: 60rpx;
    display: flex;
    align-items: center;

    .back-icon {
      width: 32rpx;
      height: 32rpx;
    }
  }

  .title {
    font-size: 36rpx;
    font-weight: 500;
    color: #000000;
    flex: 1;
    text-align: center;
  }

  .placeholder {
    width: 60rpx;
  }
}

.form-container {
  padding: 32rpx;

  .form-label {
    font-size: 32rpx;
    color: #333333;
    margin-bottom: 24rpx;
    display: block;
  }

  .textarea-container {
    background-color: #ffffff;
    border-radius: 12rpx;
    padding: 24rpx;
    margin-bottom: 60rpx;

    .feedback-input {
      width: 100%;
      height: 300rpx;
      font-size: 28rpx;
      color: #333333;
    }
  }

  .submit-button {
    background-color: #8B2A2A;
    color: #ffffff;
    font-size: 32rpx;
    height: 90rpx;
    line-height: 90rpx;
    border-radius: 8rpx;
    margin-top: 40rpx;
  }
}

.success-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32rpx;

  .success-icon {
    margin-bottom: 40rpx;

    .check-circle {
      width: 160rpx;
      height: 160rpx;
      background-color: #4CD964;
      border-radius: 50%;
      display: flex;
      justify-content: center;
      align-items: center;

      .check-mark {
        color: #ffffff;
        font-size: 80rpx;
        font-weight: bold;
      }
    }
  }

  .success-text {
    font-size: 32rpx;
    color: #333333;
    margin-bottom: 60rpx;
  }

  .return-button {
    background-color: #f2f2f2;
    color: #333333;
    font-size: 32rpx;
    height: 90rpx;
    line-height: 90rpx;
    border-radius: 8rpx;
    width: 240rpx;
  }
}

.bottom-bar {
  height: 34rpx;
  background-color: #f8f8f8;
  width: 100%;
  position: fixed;
  bottom: 0;
  left: 0;
  display: flex;
  justify-content: center;
  align-items: center;

  &::after {
    content: '';
    width: 140rpx;
    height: 8rpx;
    background-color: #000000;
    border-radius: 4rpx;
  }
}
</style>
